<div>
  <p-growl [value]="msgs"></p-growl>

  <h3 class="first">Single</h3>
  <p>In single mode, a row is selected on click event of a row. If the row is already selected then the row gets unselected.</p>
  <p-dataTable [value]="cars" selectionMode="single" [(selection)]="selectedCar1" dataKey="vin">
    <p-header>Single Selection</p-header>
    <p-footer>
      <div style="text-align: left">Selected Car: {{selectedCar1 ? selectedCar1.vin + ' - ' + selectedCar1.brand + ' - ' + selectedCar1.year + ' - ' +
        selectedCar1.color: 'none'}}</div>
    </p-footer>
    <p-column field="vin" header="Vin"></p-column>
    <p-column field="year" header="Year"></p-column>
    <p-column field="brand" header="Brand"></p-column>
    <p-column field="color" header="Color"></p-column>
  </p-dataTable>

  <h3>Multiple</h3>
  <p></p>
  <p-dataTable [value]="cars" selectionMode="multiple" [(selection)]="selectedCars1" dataKey="vin">
    <p-header>Multiple Selection</p-header>
    <p-column field="vin" header="Vin"></p-column>
    <p-column field="year" header="Year"></p-column>
    <p-column field="brand" header="Brand"></p-column>
    <p-column field="color" header="Color"></p-column>
    <p-footer>
      <ul>
        <li *ngFor="let car of selectedCars1" style="text-align: left">{{car.vin + ' - ' + car.brand + ' - ' + car.year + ' - ' + car.color}}</li>
      </ul>
    </p-footer>
  </p-dataTable>

  <h3>Events</h3>
  <p>DataTable provides onRowSelect and onRowUnselect as optional callbacks.</p>
  <p-dataTable [value]="cars" selectionMode="single" [(selection)]="selectedCar2" (onRowSelect)="onRowSelect($event)" (onRowUnselect)="onRowUnselect($event)"
    dataKey="vin">
    <p-header>Selection with Events</p-header>
    <p-column field="vin" header="Vin"></p-column>
    <p-column field="year" header="Year"></p-column>
    <p-column field="brand" header="Brand"></p-column>
    <p-column field="color" header="Color"></p-column>
  </p-dataTable>

  <h3>RadioButton</h3>
  <p>Single selection can also be handled using radio buttons by enabling the selectionMode property of column as "single".</p>
  <p-dataTable [value]="cars" [(selection)]="selectedCar3" dataKey="vin">
    <p-header>Single Selection</p-header>
    <p-footer>
      <div style="text-align: left">Selected Car: {{selectedCar3 ? selectedCar3.vin + ' - ' + selectedCar3.brand + ' - ' + selectedCar3.year + ' - ' +
        selectedCar3.color: 'none'}}</div>
    </p-footer>
    <p-column [style]="{'width':'38px'}" selectionMode="single"></p-column>
    <p-column field="vin" header="Vin"></p-column>
    <p-column field="year" header="Year"></p-column>
    <p-column field="brand" header="Brand"></p-column>
    <p-column field="color" header="Color"></p-column>
  </p-dataTable>

  <h3>Checkbox</h3>
  <p>Multiple selection can also be handled using checkboxes by enabling the selectionMode property of column as "multiple".</p>
  <p-dataTable [value]="cars" [(selection)]="selectedCars2" dataKey="vin">
    <p-header>Checkbox Selection</p-header>
    <p-column [style]="{'width':'38px'}" selectionMode="multiple"></p-column>
    <p-column field="vin" header="Vin"></p-column>
    <p-column field="year" header="Year"></p-column>
    <p-column field="brand" header="Brand"></p-column>
    <p-column field="color" header="Color"></p-column>
    <p-footer>
      <ul>
        <li *ngFor="let car of selectedCars2" style="text-align: left">{{car.vin + ' - ' + car.brand + ' - ' + car.year + ' - ' + car.color}}</li>
      </ul>
    </p-footer>
  </p-dataTable>

  <h3>Checkbox with Paging</h3>
  <p>
    When using checkboxes for multiple selection with paging and clicking the header checkbox, by default, items on all other
    pages will be deselected and only the current page's items will be toggled. Often, the more desired approach is to toggle
    all items across all pages. This can be accomplished by setting the "headerCheckboxToggleAllPages" property to "true"
    on your paged DataTable. Notice how the header checkbox only stays checked when all items across all pages are selected.
  </p>
  <p-dataTable [value]="cars" [(selection)]="selectedCars3" dataKey="vin" [paginator]="true" [rows]="5" [headerCheckboxToggleAllPages]="true">
    <p-header>Checkbox Multiple Selection with Paging</p-header>
    <p-column [style]="{'width':'38px'}" selectionMode="multiple"></p-column>
    <p-column field="vin" header="Vin"></p-column>
    <p-column field="year" header="Year"></p-column>
    <p-column field="brand" header="Brand"></p-column>
    <p-column field="color" header="Color"></p-column>
    <p-footer>
      <ul>
        <li *ngFor="let car of selectedCars3" style="text-align: left">{{car.vin + ' - ' + car.brand + ' - ' + car.year + ' - ' + car.color}}</li>
      </ul>
    </p-footer>
  </p-dataTable>
</div>
